<template>
  <el-dialog
    class="admin_settings"
    :class="{ admin_settings_show: isSelectAdmin }"
    :model-value="modelValue"
    title="设置管理"
    style="width: 480px; height: auto !important"
    draggable
    :modal="false"
    :append-to-body="true"
    show
    @update:model-value="handleClose"
  >
    <template #header="{ close, titleId, titleClass }">
      <div class="custom_header">
        <span>设置管理</span>
      </div>
    </template>
    <div class="locked_content">
      <div v-for="i in data" :key="i" class="admin_item">
        <div class="admin_item">
          <img v-if="i.isHave" class="manager-item" src="@/assets/live/penquan.png" alt="" />
          <img v-else class="manager-item" :src="addIcon" @click="addAdmin" />
        </div>
        <span class="admin_span">张小三</span>
        <el-button v-if="!i.isHave" type="primary" @click="addAdmin">添加</el-button>
        <el-button v-else type="primary">移除</el-button>
      </div>
    </div>

    <template #footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button @click="handleClose">确认</el-button>
    </template>
  </el-dialog>
  <SelectAdmin v-model="isSelectAdmin"></SelectAdmin>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";
import addIcon from "@/assets/live/addManage.svg";
import SelectAdmin from "./SelectAdmin.vue";
defineProps({
  modelValue: {
    // 接收父组件v-model传值
    type: Boolean,
    default: false,
  },
});
const isSelectAdmin = ref(false);
const emit = defineEmits(["update:modelValue"]);
const data = reactive([
  {
    name: "张小三",
    isHave: true,
  },
  {
    name: "张小三",
    isHave: true,
  },
  {
    name: "张小三",
    isHave: false,
  },
  {
    name: "张小三",
    isHave: false,
  },
  {
    name: "张小三",
    isHave: false,
  },
  {
    name: "张小三",
    isHave: false,
  },
]);

const addAdmin = () => {
  isSelectAdmin.value = true;
};
// 关闭对话框时通知父组件更新状态
const handleClose = () => {
  emit("update:modelValue", false);
};
</script>
<style lang="scss">
.admin_settings_show {
  visibility: hidden !important;
}
.admin_settings {
  padding: 0;
  background-color: #222222;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;

  .locked_content {
    padding: 30px 30px 20px 30px;
    color: #fff;
    font-weight: 400;
    font-size: 14px;
    line-height: 24px;
    font-style: normal;
    text-transform: none;
    display: flex;
    justify-content: space-between;
    .manager-item {
      width: 50px;
    }
    .admin_item {
      display: flex;
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: flex-start;
      align-items: center;
    }
    .admin_span {
      font-weight: 400;
      font-size: 12px;
      color: #ffffff;
      line-height: 12px;
      text-align: left;
      font-style: normal;
      text-transform: none;
      display: inline-block;
      padding: 8px 0;
    }
    .el-button {
      --el-button-bg-color: rgba(255, 255, 255, 0.1);
      --el-button-border-color: rgba(255, 255, 255, 0.1);
    }
    .el-button:hover {
      background-color: rgba(255, 255, 255, 0.1);
      border-color: rgba(255, 255, 255, 0.1);
    }
  }
  .custom_header {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-content: center;
    justify-content: flex-start;
    align-items: center;
    color: #fff;
    line-height: 15px;
  }

  .el-dialog__header {
    border-bottom: 1px solid rgba(216, 216, 216, 0.5);
    padding: 20px 20px 10px 20px;
    height: 56px;

    .el-dialog__headerbtn {
      height: 56px;
    }
  }

  .el-dialog__footer {
    padding: 15px;
    border-top: 1px solid rgba(216, 216, 216, 0.5);
    .el-button {
      height: 30px;
      --el-button-bg-color: rgba(255, 255, 255, 0.1);
      --el-button-border-color: rgba(255, 255, 255, 0.1);
    }
    .el-button:first-of-type {
      span {
        color: #8a8a8a;
      }
    }
    .el-button:last-of-type {
      span {
        color: #ff4e6c;
      }
    }
    .el-button:hover {
      background-color: rgba(255, 255, 255, 0.1);
      border-color: rgba(255, 255, 255, 0.1);
    }
  }
}
</style>
